import xlrd
from xlutils.copy import copy

# 从excel读取
def read(sheet_index):
    try:
        wb = xlrd.open_workbook("CalcTestData.xls")
        ws = wb.sheet_by_index(sheet_index)
        nrows = ws.nrows
        data = []
        for i in range(1, nrows):
            data.append(ws.row_values(i)[:4])
        return data
    except xlrd.XLRDError as e:
        print("读取Excel文件时出错:", e)
        return None

import xlrd
from xlutils.copy import copy

# 从excel读取
def read(sheet_index):
    wb = xlrd.open_workbook("CalcTestData.xls")
    ws = wb.sheet_by_index(sheet_index)
    nrows = ws.nrows
    data = []
    for i in range(1,nrows):
        data.append(ws.row_values(i)[:4])
    return data

# 写入excel
def write(sheet_index,x,y,value):
    wb = xlrd.open_workbook("CalcTestData.xls",formatting_info=True)
    wb_ = copy(wb)
    ws = wb_.get_sheet(sheet_index)
    ws.write(x,y,value)
    wb_.save("CalcTestData.xls")
